import { getAppPageConfig } from "../../../../hrpub/common/utils/utils";
import { pageTo } from 'nc-lightapp-front';


export default class MainAction{
    constructor(comp){
        this.comp = comp
        if(comp.props.use){
            comp.props.use.form('card');
            comp.props.use.editTable('list');
            comp.props.use.editTable('handover');
            comp.props.use.search('query');
        }
    }

    // appConfig ={
    //     appcode: '60092080',
    //     pagecode: '60092080nccloud'
    // }
    appConfig = getAppPageConfig()
    //获取模版
    getTemplate =()=>{
        const {props,action} = this.comp
        props.createUIDom(this.appConfig,(data)=>{
            this.getMulitiLange()
            props.meta.setMeta(data.template);
            console.log(data.template);
            props.button.setButtons(data.button)
        })
    }

    //获取多语
    getMulitiLange =()=>{
        const {props} = this.comp
        const {MultiInit,dispatch} = props
        MultiInit.getMultiLang({
            moduleId: 'gx6008',
            domainName: 'hrtrn',
            callback: (json,status,init)=>{
                dispatch({
                    type: 'main/update',
                    payload: {
                        json: json
                    }
                })
            }
        })
    }

    // 卸载
    willUnMount = () => {
        this.pubSub.unSubscribe('queryTableData');
    }

    // 事件订阅部分
    subscribe = () => {
        const {comp: {action}, pubSub} = this;
        pubSub.subscribe('queryTableData', (...args) => {
            action.pubAction.queryTableData(...args);
        });
        pubSub.subscribe('getWidgetTableData', (...args) => {
            action.pubAction.getWidgetTableData(...args);
        });
    }
    widget=(type)=>{
        const {props,action} = this.comp
        action.headAction.changeOrg(type)
    }
    Iswidget= ()=>{
        if(window.parent.document.getElementById('mainiframe')){
            console.log(window.parent.document.getElementById('mainiframe').src);
            let str = window.parent.document.getElementById('mainiframe').src;
            let type = str.split("=")[3]
            console.log(type)
            if(type){
                setTimeout(() => {
                    this.widget(type)
                }, 400);
            }
        }
        // let type = pageTo.getUrlParam('type');
        // let id = pageTo.getUrlParam('id');
        // console.log(pageTo);
        // console.log(type);
        // console.log(id);
      
    }
    setHeight=()=>{  
        const {props} = this.comp
        let height = document.documentElement.clientHeight;
        props.dispatch({
            type: 'main/update',
            payload: {
                pageHeight :  height - 150
            }
        })
        window.hh = this.comp
    }
    didMount =()=>{
       
        if(window.location.href.valueOf('localhost:3006')) window.location.hash = '#/ifr?page=201981519'
            // window.location.hash = '#?&c=60092080&p=60092080nccloud'
        this.getTemplate()
        this.setHeight()
        this.Iswidget();
        this.subscribe();
    }




}